//
//  yxpShowHUD.m
//  TestProject
//
//  Created by 杨小平 on 14-8-18.
//  Copyright (c) 2014年 yangxiaoping. All rights reserved.
//

#import "yxpShowHUD.h"

@interface yxpShowHUD ()
{
    UISwitch *_activityIndiatorSwitch;
    UISwitch *_networkActivityIndicatorSwitch;
    UIActivityIndicatorView *_activityIndicatorView;
    UIProgressView* _progressView;
}

@end

@implementation yxpShowHUD

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)switchValueChange:(UISwitch *)switchView
{
    if (_activityIndiatorSwitch==switchView) {
        if (switchView.on) {
            [_activityIndicatorView startAnimating];
        }else
        {
            [_activityIndicatorView stopAnimating];
        }
    }else if(_networkActivityIndicatorSwitch==switchView)
    {
        if (switchView.on) {
            [UIApplication  sharedApplication].networkActivityIndicatorVisible=YES;
        }else
        {
            [UIApplication  sharedApplication].networkActivityIndicatorVisible=NO;
        }
        
    }
}
- (void)initActityIndiator
{
    UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(10, 74, 200, 30)];
    label.textColor=[UIColor skyBlueColor];
    label.text=@"UIActivityIndicatorView";
    [self.view addSubview:label];
    
    //添加一个指示器开关 系统宽高 51，31  不可改变
    _activityIndiatorSwitch=[[UISwitch alloc] initWithFrame:CGRectMake(210, 74, 0, 0)];
    [_activityIndiatorSwitch setOnTintColor:[UIColor skyBlueColor]];
    [_activityIndiatorSwitch setOn:NO animated:YES];
    [self.view addSubview:_activityIndiatorSwitch];
    [_activityIndiatorSwitch addTarget:self action:@selector(switchValueChange:) forControlEvents:UIControlEventValueChanged];
    
    //添加指示器视图 系统宽高 20，20  不可改变 且这里的坐标是指指示器的中心坐标
    _activityIndicatorView = [[UIActivityIndicatorView  alloc] initWithFrame:CGRectMake(281.0,89,0.0,0.0)];
    /*
     activityIndicatorViewStyle
     UIActivityIndicatorViewStyleWhiteLarge                    大型白色指示器
     UIActivityIndicatorViewStyleWhite      标准尺寸白色指示器
     UIActivityIndicatorViewStyleGray    灰色指示器，用于白色背景
     */
    _activityIndicatorView.activityIndicatorViewStyle= UIActivityIndicatorViewStyleGray;
    //停止后是否自动隐藏
    _activityIndicatorView.hidesWhenStopped = YES;
    //可以将它附着在任何视图上，比如表格单元、或者视图：
    [  self.view addSubview:_activityIndicatorView];
    
}
- (void)initNetworkActivityIndicatorSwitch
{
    /*
     当你的应用程序使用网络时，应当在iPhone的状态条上放置一个网络指示器，警告用户正在使用网络。这时你可以用UIApplication的一个名为networkActivityIndicatorVisible的属性。通过设置这个可以启用或禁用网络指示器：
     */
    
    UILabel *label=[[UILabel alloc] initWithFrame:CGRectMake(10, 120, 260, 30)];
    label.textColor=[UIColor skyBlueColor];
    label.text=@"networkActivityIndicatorVisible";
    [self.view addSubview:label];
    
    //添加一个指示器开关 系统宽高 51，31  不可改变
    _networkActivityIndicatorSwitch=[[UISwitch alloc] initWithFrame:CGRectMake(265, 120, 0, 0)];
    [_networkActivityIndicatorSwitch setOnTintColor:[UIColor skyBlueColor]];
    [_networkActivityIndicatorSwitch setOn:NO animated:YES];
    [self.view addSubview:_networkActivityIndicatorSwitch];
    [_networkActivityIndicatorSwitch addTarget:self action:@selector(switchValueChange:) forControlEvents:UIControlEventValueChanged];
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    [self initActityIndiator];
    
    [self initNetworkActivityIndicatorSwitch];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
